package com.example.qxfw.nyqx.service.impl;

import com.example.qxfw.common.entity.qx.SpecialSrvStation;
import com.example.qxfw.nyqx.service.DroughtService;
import com.example.qxfw.nyqx.service.SoilHumidityService;
import com.example.qxfw.nyqx.service.TrsqService;
import com.example.qxfw.qxzs.service.SpecialSrvStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TrsqServiceImpl implements TrsqService {

    @Autowired
    private SoilHumidityService soilHumidityService;

    @Autowired
    private DroughtService droughtService;

    @Autowired
    private SpecialSrvStationService specialSrvStationService;

    @Value("${city}")
    private String city;

    @Override
    public List<SpecialSrvStation> getSpecialSrvStation(String type) {
        StringBuilder stationIds = new StringBuilder();
        String flag;
        if (type.equals("土壤湿度")){
            flag = "墒情";
            List<String> stationId = soilHumidityService.getStationId();
            for (String s : stationId) {
                stationIds.append("'").append(s).append("'").append(",");
            }
        } else {
            flag = "地面";
            List<String> stationId = droughtService.getStationId();
            for (String s : stationId) {
                stationIds.append("'").append(s).append("'").append(",");
            }
        }
        if (stationIds.length()!=0){
            stationIds.deleteCharAt(stationIds.length()-1);
            return specialSrvStationService.getList5(stationIds.toString(), flag, city);
        } else {
            return null;
        }

    }
}
